package tt.dz.egobus.servicemanager.vo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import tt.dz.egobus.api.commoncenter.bean.ConfigTypeBack;
import tt.dz.egobus.api.commoncenter.emuns.ConfigType;

import java.io.Serializable;

/**
 * @author Anson
 * @date 17-8-11
 * @name
 * @since 1.0.6
 */
public class ModuleViewVo implements Serializable {

    private static final long serialVersionUID = -3340998653508317257L;

    private static final Logger LOGGER = LoggerFactory.getLogger(ModuleViewVo.class);

    public ConfigTypeBack convert() {
        ConfigTypeBack pojo = new ConfigTypeBack();
        try {
            BeanUtils.copyProperties(this, pojo);
        } catch (BeansException e) {
            LOGGER.error("ModuleViewVo -> ConfigTypeBack bean拷贝异常, viewVo={}", this, e);
        }
        return pojo;
    }

    public ModuleViewVo view(ConfigTypeBack pojo) {
        try {
            BeanUtils.copyProperties(pojo, this);
        } catch (BeansException e) {
            LOGGER.error(" ConfigTypeBack ->  ModuleViewVo bean拷贝异常, viewVo={}", this, e);
        }
        return this;
    }

    /**
     * 业务码的编号
     **/
    private int code;

    /**
     * 业务的详情
     **/
    private String desc;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public ModuleViewVo() {
    }

    /**
     * 根据业务编号和业务详情初始化业务返回类
     *
     * @param code 业务编号
     * @param desc 业务详情
     */
    public ModuleViewVo(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 根据业务类型初始化业务类型的返回类
     *
     * @param type 业务类型类
     */
    public ModuleViewVo(ConfigType type) {
        this(type.getCode(), type.getDecs());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ModuleViewVo that = (ModuleViewVo) o;

        if (code != that.code) return false;
        return desc != null ? desc.equals(that.desc) : that.desc == null;
    }

    @Override
    public int hashCode() {
        int result = code;
        result = 31 * result + (desc != null ? desc.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "ModuleViewVo{" +
                "code=" + code +
                ", desc='" + desc + '\'' +
                '}';
    }
}
